import Vue from 'vue'
import App from './App.vue'
// 导入axios
import axios from "axios";
// 引入iView
import iView from 'iview';
import 'iview/dist/styles/iview.css';
// 引入路由模块
import VueRouter from 'vue-router';

//引入组件
import Login from "./pages/Login.vue";
import Admin from "./pages/Admin.vue"
import GoodsList from "./pages/GoodsList.vue";
import CategoryList from "./pages/CategoryList.vue";
import AccountList from "./pages/AccountList.vue";
import OrderList from "./pages/OrderList.vue";
import OrderEdit from "./pages/OrderEdit.vue";
import OrderDetail from "./pages/OrderDetail.vue";
// import Test from "./pages/Test.vue";




// 全局注册组件
Vue.use(iView);
Vue.use(VueRouter);

Vue.config.productionTip = false

Vue.prototype.$axios = axios
axios.defaults.baseURL = "http://localhost:8899";

// 路由的配置
const routes = [
        { path: "/", redirect: "/admin" },
        { path: "/login", component: Login, meta: "登录" },
        {
            path: "/admin",
            component: Admin,
            redirect: "/admin/order-list",
            // redirect: "/admin/test",
            meta: "管理后台",
            children: [
                { path: "goods-list", component: GoodsList, meta: "商品列表" },
                { path: "category-list", component: CategoryList, meta: "商品管理" },
                { path: "account-list", component: AccountList, meta: "会员列表" },
                { path: "order-list", component: OrderList, meta: "订单管理" },
                { path: "order-edit/:id", component: OrderEdit, meta: "编辑订单" },
                { path: "order-detail/:id", component: OrderDetail, meta: "订单详情" },
                // {path:"test",component:Test,meta:"订单详情"},
            ]
        },

    ]
    // 路由对象
const router = new VueRouter({ routes })

// router.beforeEach((to, from, next) => {
//     //store的getters中定义获取用户信息的函数  getUser
//     //userId为空说明用户未登录
//     let isLogin = sessionStorage.getItem("islogin")
//     if (isLogin == "nologin") {//未登录
//         if (to.path !== '/login') {//跳转到登录页
//             return next({path: '/login'});
//         }else {
//             next();
//         }
//     }else if(isLogin == "logined"){//已登录
//         if (to.path === '/login') {//跳转到首页
//             return next({path: '/admin'});
//         }
//         next();
//     }
// });
new Vue({
    router,
    render: h => h(App),
}).$mount('#app')